from bottle import route, get, post, request, run, jinja2_view

@route('/')
@jinja2_view('index.html')
def index():
    params = {
            'title': 'hello, bottle!',
            'elems': ('spam', 'egg'),
            }
    return params

@get('/login')
def login_form():
    return '''
    <form method="post">
        <label>Username: <input name="username" type="text" /></label><br />
        <label>Passowrd: <input name="password" type="password" /></label><br />
        <input type="submit" />
    </form>
    '''
@post('/login')
def login_post():
    username = request.forms.get('username')
    passname = request.forms.get('password')
    return '''
    login successfully! %s
    ''' % username

@get('/json')
def get_json():
    data = {
            'from': 'kavinyao',
            'to'  : 'sheimi',
            'message' : 'I found a nice bottle',
            'extra_data': [i for i in range(10)],
            }
    return data

run()
